/*
//
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2007-2008 Intel Corporation. All Rights Reserved.
//
//
*/

#ifndef __UMC_AVS_CONTEXT_H
#define __UMC_AVS_CONTEXT_H

#include "ippdefs.h"
#include "umc_structures.h"
#include "umc_video_data.h"

namespace UMC
{

// forward declaration of used classes
class AVSFrame;

//
// Structure to hold parameters for memory copying
struct AVS_COPY_CONTEXT
{
    AVSFrame *m_pSrc;                                           // (AVSFrame *) just encoded frame
    MediaData *m_pDst;                                          // (MediaData *) destination buffer
};


//
// Structure to hold parameters for color conversion
//

struct AVS_COLOR_CONVERTING_CONTEXT
{
    VideoData m_picSrc;                                         // (VideoData) source picture's parameters
    VideoData *m_pPicDst;                                       // (VideoData *) destination picture's parameters
};

//
// Structure to hold base parameters,
// which are common in other contexts
//

// forward declaration of used types
class AVSSlice;
struct AVS_SEQUENCE_HEADER;
struct AVS_PICTURE_HEADER;
struct AVS_SLICE_HEADER;
struct AVS_MB_INFO;
class MeFrame;

struct AVS_BASE_CONTEXT
{
    // declare the destructor to avoid some warnings
    virtual
    ~AVS_BASE_CONTEXT(void){};

    AVSSlice *m_pSlice;                                         // (AVSSlice *) pointer to the owning slice

    const AVS_SEQUENCE_HEADER *m_pSeqHeader;                   // (const AVS_PICTURE_HEADER *) pointer to the sequence's header
    const AVS_PICTURE_HEADER *m_pPicHeader;                    // (const AVS_PICTURE_HEADER *) pointer to the picture's header
    const AVS_SLICE_HEADER *m_pSlcHeader;                      // (const AVS_SLICE_HEADER *) pointer to the slice's header

    AVS_MB_INFO *m_pMBInfo;                                     // (AVS_MB_INFO *) pointer to corresponding MB info structure

    Ipp32s MbX;                                                 // (Ipp32s) current X position of macroblock
    Ipp32s MbY;                                                 // (Ipp32s) current Y position of macroblock

    Ipp32s isSecondField;                                       // (Ipp32s) ordinal number of a field
    Ipp32u iNumberOfBlocks;                                     // (Ipp32u) number of blocks per a macroblock

    Ipp32s MbFirst;                                             // (Ipp32s) number of the first macroblock in a slice
    Ipp32s MbLast;                                              // (Ipp32s) number of the last macroblock inf a slice

    Ipp32s MbIndex;                                             // (Ipp32s) number of current macroblock
    Ipp32s MbWidth;                                             // (Ipp32s) picture's width in macroblocks
    Ipp32s MbHeight;                                            // (Ipp32s) picture's height in macroblocks

    Ipp32u FixedQP;                                             // (Ipp32u) value of fixed QP if any
    Ipp32u PreviousQP;                                          // (Ipp32u) QP of the previous macroblock

    Status m_statusTask;                                        // (Status) status of the processed task
};

//
// Structure to hold parameters
// referencing current entropy decoding state
//

struct AVS_BIT_STREAM_CONTEXT
{
    union
    {
    const Ipp32u *src;                                          // (const Ipp32u *) pointer to bit stream data
    Ipp32u *dst;                                                // (Ipp32u *) pointer to destination bit stream
    };
    union
    {
    const Ipp32u *srcEnd;                                       // (const Ipp32u *) pointer to the end of bit stream data
    Ipp32u *dstEnd;                                             // (Ipp32u *) pointer to the end of destination bit stream
    };
    Ipp32s offset;                                              // (Ipp32s) current bit offset
};

struct AVS_DECODING_CONTEXT : public AVS_BASE_CONTEXT
{
    AVS_BIT_STREAM_CONTEXT m_stream;                            // (AVS_BIT_STREAM_CONTEXT) current bit stream position

    Ipp16s *m_pCoeffs;                                          // (Ipp16s *) pointer to coefficient buffer

    Ipp32s SkipMbCount;                                         // (Ipp32s) number of macroblocks to skip

    Ipp32s ScanType;                                            // (Ipp32s) type of inverse scan
};

//
// Structure to hold parameters
// referencing current reconstructing state
//

struct AVS_RECONSTRUCTING_CONTEXT : public AVS_BASE_CONTEXT
{
    const Ipp16s *m_pCoeffs;                                    // (const Ipp16s *) pointer to coefficient buffer

    union
    {
    Ipp8u *(m_pPlanes8u[3]);                                    // (Ipp8u *([])) array of pointers to the being reconstructed macroblock
    Ipp16u *(m_pPlanes16u[3]);                                  // (Ipp16u *([])) array of pointers to the being reconstructed macroblock
    };
    Ipp32s m_iPitch;                                            // (Ipp32s) pitch of planes

};

//
// Structure to hold parameters
// referencing current picture post processing state
//

struct AVS_DEBLOCKING_CONTEXT : public AVS_BASE_CONTEXT
{
    Ipp32u deblocking_disabled;                                 // (Ipp32u) deblocking process is not present in this stream

    union
    {
    Ipp8u *(m_pPlanes8u[3]);                                    // (Ipp8u *([])) array of pointers to the being reconstructed macroblock
    Ipp16u *(m_pPlanes16u[3]);                                  // (Ipp16u *([])) array of pointers to the being reconstructed macroblock
    };
    Ipp32s m_iPitch;                                            // (Ipp32s) pitch of planes

};

//
// Structure to hold parameters
// referencing current disassembling stats
//

struct AVS_DISASSEMBLING_CONTEXT : public AVS_BASE_CONTEXT
{
    Ipp16s *m_pCoeffs;                                          // (Ipp16s *) pointer to coefficient buffer

    union
    {
    Ipp8u *(m_pPlanes8u[3]);                                    // (Ipp8u *([])) array of pointers to the reconstructed macroblock
    Ipp16u *(m_pPlanes16u[3]);                                  // (Ipp16u *([])) array of pointers to the reconstructed macroblock
    };

    union
    {
    const Ipp8u *(m_pSrcPlanes8u[3]);                           // (const Ipp8u *([])) array of pointers to the source macroblock
    const Ipp16u *(m_pSrcPlanes16u[3]);                         // (const Ipp16u *([])) array of pointers to the source macroblock
    };

    Ipp32s m_iPitch;                                            // (Ipp32s) pitch of planes

};

struct AVS_ME_CONTEXT : public AVS_BASE_CONTEXT
{
    union
    {
    const Ipp8u *(m_pSrcPlanes8u[3]);                           // (const Ipp8u *([])) array of pointers to the source macroblock
    const Ipp16u *(m_pSrcPlanes16u[3]);                         // (const Ipp16u *([])) array of pointers to the source macroblock
    };
    Ipp32s m_iPitch;                                            // (Ipp32s) pitch of planes

    MeFrame *m_pMeFrame[8];                                     // (MeFrame *[]) pointer on the first MeFrame
    Ipp32u  m_meMask;
};

} // namespace UMC

#endif // __UMC_AVS_CONTEXT_H
